package function;

import course.Course;
import course.CourseList;

import java.util.Scanner;

public class FindFunction implements IFunction{
    @Override
    public void work(CourseList courseList) {
        System.out.println("查找课程");
        System.out.println("请输入课程名称");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();//通过书名查找
        int correntsize=courseList.getUsedsize();//获取课程数组元素个数，
        for (int i = 0; i <correntsize ; i++) {//遍历数组以获取对于查找元素的下标
            Course course=courseList.getCourse(i);//获取数组中元素
            if (course.getName().equals(name)){
                System.out.println("找到了该门课");
                System.out.println(course);//找到了就显示
                return;
            }
        }
        System.out.println("没有这门课程");
    }
}
